import './util/init-leancloud-sdk'; //初始化leancloud的sdk
import { history } from 'umi';
import HeaderDropMenu from './components/HeaderDropMenu';

// 初始化某些全局数据的运行时配置
export async function getInitialState() {
  const useState = JSON.parse(window.localStorage.getItem('useInfo')) || {
    isLogin: false,
    userInfo: null,
  };
  return useState;
}

//layout的运行时配置，自定义控制layout的渲染逻辑
export const layout = ({ initialState }) => {
  return {
    onPageChange: () => {
      if (!initialState.isLogin) {
        history.push('/login');
      }
    },
    // 渲染顶部右边菜单
    rightContentRender: () => <HeaderDropMenu />,
  };
};
